﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ManagerStaff
{
    public partial class FormLogin : Form
    {
        private SqlConnection connect;
        public FormLogin()
        {
            InitializeComponent();
        }

        private void doClose()
        {
            this.Close();
        }

        private void pn_login_close_MouseClick(object sender, MouseEventArgs e)
        {
            doClose();
        }

        private void lb_more_info_Click(object sender, EventArgs e)
        {
            doShowWarning();
        }

        private void lb_lost_password_Click(object sender, EventArgs e)
        {
            doShowWarning();
        }

        private void lb_new_account_Click(object sender, EventArgs e)
        {
            doShowWarning();
        }

        private void lb_need_help_Click(object sender, EventArgs e)
        {
            doShowWarning();
        }

        private void lb_more_info_MouseEnter(object sender, EventArgs e)
        {
            doChangeFontEnter(lb_more_info);
        }
    
        private void lb_lost_password_MouseEnter(object sender, EventArgs e)
        {
            doChangeFontEnter(lb_lost_password);
        }

        private void lb_new_account_MouseEnter(object sender, EventArgs e)
        {
            doChangeFontEnter(lb_new_account);
        }

        private void lb_need_help_MouseEnter(object sender, EventArgs e)
        {
            doChangeFontEnter(lb_need_help);
        }


        private void lb_more_info_MouseLeave(object sender, EventArgs e)
        {
            doChangeFontLeave(lb_more_info);
        }

        private void lb_lost_password_MouseLeave(object sender, EventArgs e)
        {
            doChangeFontLeave(lb_lost_password);
        }

        private void lb_new_account_MouseLeave(object sender, EventArgs e)
        {
            doChangeFontLeave(lb_new_account);
        }

        private void lb_need_help_MouseLeave(object sender, EventArgs e)
        {
            doChangeFontLeave(lb_need_help);
        }

        private void bt_login_Click(object sender, EventArgs e)
        {
            doCheckLogin();
        }
// ------------------------- phuong thuc chung ----------------------------------
        private void doShowWarning()
        {
            MessageBox.Show("Coming soon! Please Wait ^^!");
        }

        private void doChangeFontEnter(Label x)
        {
            x.Font = new Font("Times New Roman", 7, FontStyle.Underline);
        }


        private void doChangeFontLeave(Label x)
        {
            x.Font = new Font("Times New Roman", 7, FontStyle.Bold);
        }

        private void doReset()
        {
            ccbox_username.Text = "";
            txt_password.Text = "";
            cb_remember_me.Checked = false;
        }
        private void doCheckLogin()
        {
            doConnectDatabaseLogin();
            SqlCommand com;
            com = new SqlCommand("SELECT * FROM DANGNHAP WHERE ID = @USERNAME", connect);
            com.Parameters.AddWithValue("@USERNAME", ccbox_username.Text.Trim());
            object a = com.ExecuteScalar();
            if (a == null)
            {
                doReset();
                ccbox_username.Focus();
                return;
            }
            com = new SqlCommand("SELECT * FROM DANGNHAP WHERE ID = @USERNAME AND PASS = @PASSWORD", connect);
            com.Parameters.AddWithValue("@USERNAME", ccbox_username.Text.Trim());
            com.Parameters.AddWithValue("@PASSWORD", txt_password.Text.Trim());
            a = com.ExecuteScalar();
            if (a != null)
            {
                FormMain main = new FormMain();
                main.Show();
                this.Visible = false;
                return;
            }
            txt_password.Text = "";
            txt_password.Focus();
        }

        private void doConnectDatabaseLogin()
        {
            string cn = "Data Source=SUNRISE;Initial Catalog=QuanLyNhanSu;User ID=sa;Password=12345";
            try 
            {
                connect = new SqlConnection(cn);
                connect.Open();
            }
            catch(Exception ex)
            {
                MessageBox.Show("Connect close!");
            }
        }

     
// ------------------------- End phuong thuc chung ----------------------------------
       
    }

}
